package cn.mazexal.exambg.common.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.sql.Connection;

/**
 * @author: Mazexal
 * Date: 2025/6/3
 */
@Configuration
public class ConnectionPoolWarmup {

    @Bean
    public CommandLineRunner warmupHikari(DataSource dataSource) {
        return args -> {
            HikariDataSource hds = (HikariDataSource) dataSource;
            try (Connection conn = hds.getConnection()) {
                System.out.println("✅ 连接池预热完成 | 活跃连接: " + hds.getHikariPoolMXBean().getActiveConnections());
            }
        };
    }
}